// Get statistics about the swimmers performance from the swimPerformance table
// and display it for the selected swimmer in the dropdown box.
function getSwimmerPerformance() {
	// Get the ajax object.
	var xmlhttp = getAjaxObject();
	
	xmlhttp.onreadystatechange=function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			// Display a table of the swimmers performance history
			document.getElementById("displaySwimPerf").innerHTML = xmlhttp.responseText;
		}
	}
	
	var e = document.getElementById("swimmers");
	var data = "swimmerID=" + e.options[e.selectedIndex].value + "&name=" + e.options[e.selectedIndex].text;
	// Send the swimmerID and get a table of the swimmer performance.
	xmlhttp.open("POST", "./ajax_swimmerPerformance/getSwimmerPerformance.php", true);
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(data);
}

// Create and return an ajax object.
function getAjaxObject() {
	var xmlhttp = null;
	try {
		xmlhttp = new XMLHttpRequest();
	}
	catch(err) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(err) {
			alert("Error, your browser does not support AJAX");
		}
	}
	return xmlhttp;
}